package cn.com.callback


import cn.com.elite.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.Util;
import net.sf.json.JSONObject;
import cn.com.kh.KHUtil;

/**
 * 
 * @author xrm
 * @use 获取业务信息
 *
 *
 */
public class GetPayment implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(GetPayment.class);
	private String charset = "utf-8"; //设置字符集
	private int timeout = 100000; //设置请求超时时间
	private int enableSSLflag = 1;
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json");
		JSONObject result = new JSONObject();
		def smap,oJson,SaveResult;
		try {
			//获取客户端传参 stStorecontractoid
			def r_dangweioid = Util.filterForObject(request.getParameter("dangweioid")); //获取客户oid
			def r_stStorecontractoid = Util.filterForObject(request.getParameter("stStorecontractoid")); //获取客户oid
			log.debug("NGS传参:"+r_dangweioid+"客户"+r_stStorecontractoid);
			//传参处理

			//列表接口调用
			if(r_dangweioid.equals("")&&r_stStorecontractoid.equals("")) {
				result.put("code", "-1");
				result.put("msg", "未传递参数！");
				return result
			}
			Map<String, String> map = new HashMap<String, String>();
				map.put("dangweioid", r_dangweioid);
			    map.put("stStorecontractoid", r_stStorecontractoid);
				map.put("key", "ca3c64a49d1f11ecbed6d703198897725e7aba55");
			def	ASCIIMD5 = KHUtil.ASCIIORDER(map);
			log.debug("接口返回:"+ASCIIMD5);

			oJson = CustHttpPort(eliteBean,ASCIIMD5); //调用接口方法

			log.debug("接口返回:"+oJson);
			return	oJson;


		}catch (Exception e) {
			log.error("errormsg:", e)
			result.put("code", "-1");
			result.put("msg", "调用失败！");
			return result;
		}
	}


/**
 * 
 * @use 业务历史接口调用
 * @param eliteBean
 * @param Custname,Mobile,Idno,Custnameid
 * @return
 */
	private String CustHttpPort(EliteBean eliteBean,ASCIIMD5) {
		JSONObject result = new JSONObject();
		def smap,mopsmap,chatqueue,customer_guid,url="";
		try {
			//获取接口地址
			smap = eliteBean.chaxun_sql("select target_url as url from sys_interface_config where type ='getCustomerFeeItemList'","dataSource");
			if(smap.size()==0) {
				result.put("msg", "找不到对应接口");
				result.put("code", "-1");
				return result;
			}else{
				 url = smap[0].getAt("url");
			};



			def postmap=Util.doHttpPost(url,ASCIIMD5.toString(),charset,timeout,enableSSLflag);
			log.debug("接口返回:"+postmap);
			JSONObject obj = JSONObject.fromObject(postmap);
			if(obj.getInt("status")!=200) {
				result.put("code","-1");
				result.put("msg", "接口调用异常");
				return result;
			}else{
				return obj;
			};

		}catch (Exception e) {
			log.error("errormsg:", e)
			result.put("code", "-1");
			result.put("msg", "程序异常");
			return result;
		}
	}




}








